﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing.Imaging;
using Lamex.Interface;
using Lamex.Base;
using Lamex.mDashboard.BLL;
using System.Xml;
using DevExpress.XtraEditors.Controls;
using Lamex.Common;
using System.Resources;
using System.Reflection;
using Lamex.mDashboard.en_us;
using Lamex.mDashboard.zh_Hans;
using Lamex.Library.CommonClass;

namespace Lamex.mDashboard.UI
{
    public partial class FrmPANELAssemblyQuery : frmBaseChild
    {
        Lamex.mDashboard.ucControls.ucShowPic ucShowPicList = null;
        ResourceManager rm = null;
        public FrmPANELAssemblyQuery()
        {
            InitializeComponent();
            this.Load += new EventHandler(this.FrmPANELAssemblyQuery_Load);
            DataTable dt = new DataTable();
            gcView.Click += new EventHandler(gcView_Click);
            this.TextChanged += new EventHandler(FrmPANELAssemblyQuery_TextChanged);
            //dt.Columns.Add(new DataColumn("gc1"));

            //dt.Columns.Add("gc2", System.Type.GetType("System.Byte[]"));
            ////
            //string img = "tel.png";
            //dt.Rows.Add(GetRow(dt, "张三", img));
            //dt.Rows.Add(GetRow(dt, "张三", img));

            //gridView1.RowHeight = 100;
            ////gridView1.OptionsView.RowAutoHeight = true;
            //gvShow.DataSource = dt;
            plMid.Visible = false;
            //Plright.Visible = false;


        }
        private void FrmPANELAssemblyQuery_TextChanged(object sender, EventArgs e)
        {
            ChangeLanguage();
        }
        private void FrmPANELAssemblyQuery_Load(object sender,EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理

            //DataTable dt  = BaseFactory<B_PL_DailyWorkList>.Instance.GetDataTableBySql("select * from B_PL_DailyWorkList where ");
            txtAUFNR.UcTableName = "B_PL_DailyWorkList";
            txtAUFNR.UcValueMember= "AUFNR";


            txtAUFNR.InitItme(" and isnull(RECORDFLAG,'')='' and isnull(COLORA,'')!='' and len(AUFNR)=12");

            
            txtAUFNR.InitItme(" and isnull(RECORDFLAG,'')='' and isnull(COLORA,'')!='' and len(AUFNR)=12");

            txtAUFNR.UcProperties.TextEditStyle = TextEditStyles.Standard;
            txtAUFNR.UcProperties.ShowHeader = false;
            if (Loginer.CurrentUser.Account == "TY Chan" || Loginer.CurrentUser.Account == "Rocky He")
                txtAUFNR.Text = "633554017809";
            //Init();
            ChangeLanguage();
        }
        private void ChangeLanguage()
        {
            if (Loginer.CurrentUser.ChangeLanguage == 0)
            {
                rm = new ResourceManager(PanelCNResource.ResourceManager.BaseName, Assembly.GetExecutingAssembly());

            }
            else
            {
                rm = new ResourceManager(PanelENResource.ResourceManager.BaseName, Assembly.GetExecutingAssembly());
            }

            this.Text = rm.GetString("FrmPANELAssemblyQuery");
            txtAUFNR.Caption = rm.GetString("txtAUFNR");
            txtUPPSMNG.Caption = rm.GetString("txtUPPSMNG");
            txtGROES.Caption = rm.GetString("txtGROES");
            txtP4_AL_COLOR.Caption = rm.GetString("txtP4_AL_COLOR");
            txtP4_LR.Caption = rm.GetString("txtP4_LR");
            txtTRUNK_TYPE.Caption = rm.GetString("txtTRUNK_TYPE");
            txtPANEL_POS.Caption = rm.GetString("txtPANEL_POS");
            txtHeight.Caption = rm.GetString("txtHeight");
            txtWidth.Caption = rm.GetString("txtWidth");

            LanguageObject.RegisterLanguage(gridView2);
      
        }
        public override void DoView(IButtonInfo sender)
        {
            try
            {
                 ShowPanelData();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
                txtAUFNR.Text = "";
            }
            base.DoView(sender);
        }
        LabelControl sublb2 = null;
        LabelControl sublb1Rigth = null;
        DevExpress.XtraEditors.PanelControl panelControl4 = null;
        DevExpress.XtraEditors.PanelControl panelControl3 = null;
        private void txtAUFNR_UcTextKeyPress(object sender, KeyPressEventArgs e)

        {
            try
            {
                if (e.KeyChar == 13)
                {
                    ShowPanelData();
                }
            }
            catch(Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
                txtAUFNR.Text = "";
            }
        }
        /// <summary>
        /// show the panel dataset method
        /// </summary>
        private void ShowPanelData()
        {
            if (string.IsNullOrEmpty(txtAUFNR.Text))
            {
                XtraMessageBox.Show("数据不能为空！");
                return;
            }
            if (txtAUFNR.Text.Length < 12)
            {
                XtraMessageBox.Show("长度小于12位！");
                return;
            }

            string OrderNum = txtAUFNR.Text.Substring(0, 12);
            Model.B_PL_DailyWorkListInfo dailymodel = BaseFactory<B_PL_DailyWorkList>.Instance.GetEntriyList(" 1=1 and AUFNR='" + OrderNum + "'").FirstOrDefault();
            List<Model.B_PL_AluminumFollowUpListInfo> alumList = BaseFactory<B_PL_AluminumFollowUpList>.Instance.GetEntriyList(" 1=1 and AUFN='" + OrderNum + "'");
            List<Model.B_PL_FabricFollowUpListInfo> fabriList = BaseFactory<B_PL_FabricFollowUpList>.Instance.GetEntriyList(" 1=1 and AUFNR='" + OrderNum + "'");
            DataTable detailList = BaseFactory<B_PL_DailyWorkList>.Instance.GetDetailList(OrderNum);
            if (dailymodel != null)
            {

                plsubLeft.Controls.Clear();
                txtUPPSMNG.Text = dailymodel.UPPSMNG;
                txtGROES.Text = dailymodel.GROES;
                txtP4_AL_COLOR.Text = dailymodel.P4_AL_COLOR;
                txtP4_LR.Text = dailymodel.P4_LR;
                txtPANEL_POS.Text = dailymodel.PANEL_POS;
                txtTRUNK_TYPE.Text = dailymodel.TRUNK_TYPE;

                gcView.DataSource = detailList;

                if (dailymodel != null)
                {
                    txtUPPSMNG.Text = dailymodel.UPPSMNG;
                    txtGROES.Text = dailymodel.GROES;
                    txtP4_AL_COLOR.Text = dailymodel.P4_AL_COLOR;
                    txtP4_LR.Text = dailymodel.P4_LR;
                    txtPANEL_POS.Text = dailymodel.PANEL_POS;
                    txtTRUNK_TYPE.Text = dailymodel.TRUNK_TYPE;
                    txtHeight.Text = dailymodel.S_HEIGHT;
                    txtWidth.Text = dailymodel.S_WIDTH;
                    string[] Array = dailymodel.COLORA.Split('/');
                    string[] Brray = dailymodel.COLORB.Split('/');
                    string[] Hrray = dailymodel.PSKO_HEIGHT.Split('/');
                    if (string.IsNullOrEmpty(dailymodel.COLORA) || string.IsNullOrEmpty(dailymodel.COLORB) || string.IsNullOrEmpty(dailymodel.PSKO_HEIGHT))
                    {
                        XtraMessageBox.Show("此生产订单非屏风");

                        return;
                    }
                    int irow = Array.Length;
                    DataTable dt = new DataTable();
                    dt.Columns.Add(new DataColumn("SortIndex"));
                    dt.Columns.Add(new DataColumn("PSKO_HEIGHT"));
                    dt.Columns.Add("COLORA", System.Type.GetType("System.Byte[]"));
                    dt.Columns.Add("COLORAName");
                    dt.Columns.Add("COLORB", System.Type.GetType("System.Byte[]"));
                    dt.Columns.Add("COLORBName");
                    dt.Columns.Add("Proportion");

                    string filename = "";
                    int Count = 0;
                    string filenameSJ = "";
                    string ReplyPath = "";
                    string fibirlPath = "";
                    string splitPath = "";
                    XmlDocument doc = new XmlDocument();
                    doc.Load(Application.StartupPath + "\\PicturePathConfig.xml");
                    XmlNode xn = doc.SelectSingleNode("Pictures");
                    XmlNodeList xnl = xn.ChildNodes;


                    foreach (XmlNode xn1 in xnl)
                    {
                        XmlElement xe = (XmlElement)xn1;
                        XmlNodeList xn2 = xe.ChildNodes;
                        foreach (XmlElement x2 in xn2)
                        {
                            if (x2.Name == "PanelPath")
                                filename = x2.InnerText;//读取标准图片路径
                            if (x2.Name == "iPageSum")
                                Count = Convert.ToInt32(x2.InnerText);//读取张数
                            if (x2.Name == "panelSjPath")
                                filenameSJ = x2.InnerText;//读取临时图片路径
                            if (x2.Name == "ReplyPath")
                                ReplyPath = x2.InnerText; //读取申请图片路径
                            if (x2.Name == "PanelPath")
                                fibirlPath = x2.InnerText; //读取布置图片路径
                            if (x2.Name == "panlSdPath")
                                splitPath = x2.InnerText; //读取切割显示图路径
                        }
                    }
                    int length = Array.Length;
                    int hLength = Hrray.Length;
                    int m = 0;
                    decimal iTotal = 0;
                    int iSplitLine = 0;

                    if (length == 1)
                    {
                        //设默认值是100，目的是为了数据能在表格里自动分配高度
                        DataRow dr = GetRow(dt, "第" + (1).ToString() + "格", "300", Array[0], Brray[0], fibirlPath);
                        iTotal += 300;
                        dt.Rows.Add(dr);
                    }
                    else
                    {
                        for (int i = 0; i < length; i++)
                        {
                            if (Array[length - i - 1] == "N")
                            {
                                //设默认值是100，目的是为了数据能在表格里自动分配高度
                                DataRow dr = GetRow(dt, "第" + (length - i).ToString() + "格", "120", Array[length - i - 1], Brray[length - i - 1], fibirlPath);
                                iTotal += 100;
                                dt.Rows.Add(dr);
                            }
                            else
                            {

                                DataRow dr = GetRow(dt, "第" + (length - i).ToString() + "格", Hrray[hLength - m - 1], Array[length - i - 1], Brray[length - i - 1], fibirlPath);
                                if (string.IsNullOrEmpty(Hrray[hLength - m - 1].ToString().Trim()))
                                {
                                    XtraMessageBox.Show("产品数据有问题！");
                                    txtAUFNR.Text = "";
                                    return;
                                }
                                iTotal += decimal.Parse(Hrray[hLength - m - 1]);
                                dt.Rows.Add(dr);
                                m++;
                            }
                        }
                    }
                    //填充最后一行数据为标题，目的是不显示标题
                    DataRow drow = null;
                    if (Loginer.CurrentUser.ChangeLanguage == 0)
                        drow = GetRow(dt, "分格", "0", "A面", "B面", fibirlPath);
                    else
                        drow = GetRow(dt, "分格", "0", "A Side", "B Side", fibirlPath);
                    //iTotal += 120;
                    dt.Rows.Add(drow);
                    for (int j = 0; j < dt.Rows.Count; j++)
                    {
                        if (dt.Rows[j]["PSKO_HEIGHT"].ToString() == "150")
                        {
                            iSplitLine = j;
                        }
                    }

                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["PSKO_HEIGHT"].ToString() != "SortIndex")
                            dr["Proportion"] = Math.Round(decimal.Parse(dr["PSKO_HEIGHT"].ToString()) / iTotal, 3);
                    }


                    int p1Height = plsubLeft.Height - 30;
                    int p1Width = plsubLeft.Width;
                    int midLength = p1Width / 2;
                    panelControl4 = new PanelControl();
                    panelControl3 = new PanelControl();

                    // 
                    // panelControl3
                    // 
                    panelControl3.Dock = System.Windows.Forms.DockStyle.Left;
                    //panelControl3.Location = new System.Drawing.Point(2, 2);
                    panelControl3.Name = "panelControl3";
                    panelControl3.Width = midLength;
                    //panelControl3.Size = new System.Drawing.Size(165, 332);
                    panelControl3.TabIndex = 0;
                    //panelControl3.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                    panelControl3.Margin = new Padding(-1, -1, -1, -1);
                    //panelControl3.Resize += new EventHandler(panelControl3_Resize);
                    // 
                    // panelControl4
                    // 
                    panelControl4.Dock = System.Windows.Forms.DockStyle.Fill;
                    //panelControl4.Location = new System.Drawing.Point(167, 2);
                    panelControl4.Name = "panelControl4";
                    //panelControl4.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                    panelControl4.Width = midLength;
                    panelControl4.Margin = new Padding(-1, -1, -1, -1);
                    panelControl4.TabIndex = 1;
                    //panelControl4.Resize += new EventHandler(panelControl4_Resize);

                    int heigthhAll = 0;
                    int lastHeigth = 0;
                    int x = 0;
                    int y = 0;
                    ucShowPicList = new ucControls.ucShowPic();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        int ifontSize = p1Height / 60;
                        int h = 0;
                        if (dt.Rows[i]["SortIndex"].ToString() != "分格")
                            h = (int)(float.Parse(p1Height.ToString()) * float.Parse(dt.Rows[i]["Proportion"].ToString()));
                        else
                            h = 30;

                        if (i != 0)
                            y += lastHeigth;

                        if (i < dt.Rows.Count - 1)
                        {
                            LabelControl sublb1 = new LabelControl();
                            sublb1Rigth = new LabelControl();
                            sublb1.Text = dt.Rows[i]["SortIndex"].ToString() + ":" + dt.Rows[i]["PSKO_HEIGHT"].ToString();
                            //sublb1.AutoSize = true;
                            sublb1.Font = new Font("Arial Unicode MS", ifontSize, FontStyle.Bold);
                            sublb1.BackColor = Color.White;
                            sublb1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;

                            sublb1Rigth.Text = dt.Rows[i]["COLORAName"].ToString();
                            sublb1Rigth.Font = new Font("Arial Unicode MS", ifontSize, FontStyle.Bold);
                            //sublb1Rigth.Anchor = AnchorStyles.Right;
                            //sublb1Rigth.Anchor = AnchorStyles.Top;
                            //sublb1Rigth.RightToLeft = RightToLeft.Yes;
                            //sublb1Rigth.Dock = DockStyle.Top;
                            //sublb1Rigth.atu
                            sublb1Rigth.BackColor = Color.White;
                            sublb1Rigth.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                            sublb1Rigth.BringToFront();


                            sublb2 = new LabelControl();
                            sublb2.Text = dt.Rows[i]["COLORBName"].ToString();
                            //sublb2.AutoSize = true;
                            sublb2.BackColor = Color.White;
                            sublb2.Font = new Font("Arial Unicode MS", ifontSize, FontStyle.Bold);
                            //sublb2.Anchor = AnchorStyles.Left;
                            //sublb2.Anchor = AnchorStyles.Top;
                            //sublb2.Dock = DockStyle.Top;
                            sublb2.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                            PictureEdit picEidtColorA = new PictureEdit();
                            PictureEdit picEidtColorB = new PictureEdit();
                            PictureEdit picEidtsubA = new PictureEdit();
                            PictureEdit picEidtsubB = new PictureEdit();
                            string trunkType = "";
                            if (string.IsNullOrEmpty(dailymodel.TRUNK_TYPE))
                                trunkType = "";
                            else
                                trunkType = dailymodel.TRUNK_TYPE.ToLower();

                            if (dailymodel.GROES.ToLower().Contains("tvb") || trunkType == "l" || trunkType == "r")//包含tvb的是要切割的数据数
                            {
                                if (string.IsNullOrEmpty(dailymodel.TRUNK_TYPE))
                                {
                                    if (i <= iSplitLine)//小于等于最底一个150的不切
                                    {
                                        NormalFibri(picEidtsubA, picEidtsubB, picEidtColorA, picEidtColorB, sublb1Rigth, sublb1, sublb2, dt, midLength, h, x, y, i);

                                    }
                                    else
                                    {
                                        LeftFibri(picEidtsubA, picEidtsubB, picEidtColorA, picEidtColorB, sublb1Rigth, sublb1, sublb2, dt, midLength, h, x, y, i, splitPath);

                                    }
                                }
                                else
                                {
                                    if (dailymodel.TRUNK_TYPE.ToLower() == "l")
                                    {
                                        if (i <= iSplitLine)//小于等于最底一个150的不切
                                        {
                                            NormalFibri(picEidtsubA, picEidtsubB, picEidtColorA, picEidtColorB, sublb1Rigth, sublb1, sublb2, dt, midLength, h, x, y, i);

                                        }
                                        else
                                        {
                                            LeftFibri(picEidtsubA, picEidtsubB, picEidtColorA, picEidtColorB, sublb1Rigth, sublb1, sublb2, dt, midLength, h, x, y, i, splitPath);

                                        }
                                    }
                                    else
                                    {
                                        if (i <= iSplitLine)//小于等于最底一个150的不切
                                        {
                                            NormalFibri(picEidtsubA, picEidtsubB, picEidtColorA, picEidtColorB, sublb1Rigth, sublb1, sublb2, dt, midLength, h, x, y, i);

                                        }
                                        else
                                        {
                                            RightFibri(picEidtsubA, picEidtsubB, picEidtColorA, picEidtColorB, sublb1Rigth, sublb1, sublb2, dt, midLength, h, x, y, i, splitPath);

                                        }
                                    }

                                }

                            }
                            else
                            {
                                picEidtsubA.EditValue = dt.Rows[i]["COLORA"];
                                picEidtsubA.Width = midLength / 5;
                                picEidtsubA.Dock = DockStyle.Left;
                                picEidtsubA.Height = h - sublb1Rigth.Height;
                                sublb1Rigth.Location = new Point(midLength * 2 / 5, 0);



                                picEidtsubB.EditValue = dt.Rows[i]["COLORA"];
                                picEidtsubB.Width = midLength / 5;
                                picEidtsubB.Dock = DockStyle.Right;
                                picEidtsubB.Height = h - sublb1Rigth.Height;

                                //picEidtColorA.EditValue = dt.Rows[i]["COLORA"];
                                if (!string.IsNullOrEmpty(dt.Rows[i]["COLORA"].ToString()))
                                {
                                    Stream streamA = new MemoryStream((Byte[])dt.Rows[i]["COLORA"]);
                                    Bitmap bmtempA = new Bitmap(streamA);
                                    picEidtColorA.EditValue = new Bitmap(bmtempA, midLength, h);
                                }
                                else
                                {
                                    picEidtColorA.EditValue = dt.Rows[i]["COLORA"];
                                }
                                picEidtColorA.Height = h;
                                //picEidtColorA.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                                picEidtColorA.Margin = new Padding(0, 0, 0, 0);
                                picEidtColorA.Location = new Point(x, y);
                                picEidtColorA.Width = midLength;

                                picEidtColorA.Controls.Add(sublb1Rigth);
                                picEidtColorA.Controls.Add(sublb1);
                                //picEidtColorA.Controls.Add(picEidtsubA);
                                if (!string.IsNullOrEmpty(dt.Rows[i]["COLORB"].ToString()))
                                {
                                    Stream streamB = new MemoryStream((Byte[])dt.Rows[i]["COLORB"]);
                                    Bitmap bmtempB = new Bitmap(streamB);
                                    //picEidtColorB.Dock = DockStyle.Bottom;
                                    picEidtColorB.EditValue = new Bitmap(bmtempB, midLength, h);
                                }
                                else
                                {
                                    picEidtColorB.EditValue = dt.Rows[i]["COLORB"];
                                }
                                picEidtColorB.Height = h;
                                picEidtColorB.Location = new Point(x, y);
                                picEidtColorB.Width = midLength;
                                //picEidtColorB.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                                picEidtColorB.Margin = new Padding(0, 0, 0, 0);
                                sublb2.Location = new Point(midLength * 2 / 5, 0);
                                picEidtColorB.Controls.Add(sublb2);
                                //picEidtColorB.Controls.Add(picEidtsubB);
                            }

                            lastHeigth = h;


                            panelControl3.Controls.Add(picEidtColorA);
                            panelControl4.Controls.Add(picEidtColorB);
                        }
                        else
                        {

                            TextEdit txtColorA = new TextEdit();
                            txtColorA.Properties.AutoHeight = false;
                            //picEidtColorB.Dock = DockStyle.Bottom;
                            txtColorA.EditValue = dt.Rows[i]["COLORAName"];
                            txtColorA.Height = h;
                            txtColorA.Location = new Point(x, y);
                            txtColorA.Width = midLength;
                            //picEidtColorB.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                            txtColorA.Margin = new Padding(0, 0, 0, 0);
                            txtColorA.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

                            TextEdit txtColorB = new TextEdit();
                            txtColorB.Properties.AutoHeight = false;
                            //picEidtColorB.Dock = DockStyle.Bottom;
                            txtColorB.EditValue = dt.Rows[i]["COLORBName"];
                            txtColorB.Height = h;
                            txtColorB.Location = new Point(x, y);
                            txtColorB.Width = midLength;
                            txtColorB.Properties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                            //picEidtColorB.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
                            txtColorA.Margin = new Padding(0, 0, 0, 0);

                            lastHeigth = h;
                            panelControl3.Controls.Add(txtColorA);
                            panelControl4.Controls.Add(txtColorB);
                        }


                    }
                    plsubLeft.Controls.Add(panelControl4);
                    plsubLeft.Controls.Add(panelControl3);

                    //读取布置和铝材和申请图片
                    List<string> fabriIamgeList = new List<string>();
                    List<string> alumineImageList = new List<string>();
                    List<string> replyImageList = new List<string>();
                    List<Model.B_IE_PathTypeInfo> pathList = new List<Model.B_IE_PathTypeInfo>();


                    //获取布置据路径；
                    List<string> fabrisList = fabriList.Select(a => a.ZPRODWG).Distinct().ToList();
                    foreach (Model.B_PL_FabricFollowUpListInfo model in fabriList)
                    {

                        if (model != null)
                        {
                            string path = "";
                            if (model.ZCMAT.Substring(0, 3) == "396")
                            {
                                Model.B_IE_PathTypeInfo mod = new Model.B_IE_PathTypeInfo();
                                path = filenameSJ + model.ZCMAT + ".tif";
                                mod.PathName = path;
                                mod.TypeName = "F" + '_' + model.ZPRODWG;
                                //pathList.Add(mod);
                                Model.B_IE_PathTypeInfo existModel = pathList.Where(p => p.PathName == path).FirstOrDefault();
                                if (existModel == null)
                                    pathList.Add(mod);

                            }
                            else
                            {
                                for (int count = 0; count < 5; count++)
                                {
                                    Model.B_IE_PathTypeInfo mod = new Model.B_IE_PathTypeInfo();
                                    if (count == 0)
                                        path = splitPath + model.ZPRODWG + ".tif";//2020-11-22
                                    else
                                        path = splitPath + model.ZPRODWG + "-" + count + ".tif";
                                    mod.PathName = path;
                                    mod.TypeName = "F" + '_' + model.ZPRODWG;
                                    Model.B_IE_PathTypeInfo existModel = pathList.Where(p => p.PathName == path).FirstOrDefault();
                                    if (existModel == null)
                                        pathList.Add(mod);

                                }

                            }

                        }

                    }
                    //获取铝材数据路径；
                    List<string> alumsList = alumList.Select(a => a.DWGNO).Distinct().ToList();
                    foreach (Model.B_PL_AluminumFollowUpListInfo model in alumList)
                    {

                        if (model != null)
                        {
                            string path = "";
                            if (model.MATNR.Substring(0, 3) == "396")
                            {
                                Model.B_IE_PathTypeInfo mod = new Model.B_IE_PathTypeInfo();
                                path = filenameSJ + model.MATNR + ".tif";
                                mod.PathName = path;
                                mod.TypeName = "AL" + '_' + model.DWGNO;
                                //pathList.Add(mod);
                                Model.B_IE_PathTypeInfo existModel = pathList.Where(p => p.PathName == path).FirstOrDefault();
                                if (existModel == null)
                                    pathList.Add(mod);

                            }
                            else
                            {
                                for (int count = 0; count < 5; count++)
                                {
                                    Model.B_IE_PathTypeInfo mod = new Model.B_IE_PathTypeInfo();
                                    if (count == 0)
                                        path = splitPath + model.DWGNO + ".tif";
                                    else
                                        path = splitPath + model.DWGNO + "-" + count + ".tif";
                                    mod.PathName = path;
                                    mod.TypeName = "AL" + '_' + model.DWGNO;
                                    //pathList.Add(mod);
                                    Model.B_IE_PathTypeInfo existModel = pathList.Where(p => p.PathName == path).FirstOrDefault();
                                    if (existModel == null)
                                        pathList.Add(mod);
                                }

                            }

                        }

                    }
                    //获取申请数据路径；
                    //foreach (Model.B_PL_AluminumFollowUpListInfo model in alumList)
                    //{

                    if (dailymodel != null)
                    {
                        string path = "";
                        //if (dailymodel.MATNR.Substring(0, 3) == "396")
                        //{
                        //    Model.B_IE_PathTypeInfo mod = new Model.B_IE_PathTypeInfo();
                        //    path = ReplyPath + model.MATNR + ".tif";
                        //    mod.PathName = path;
                        //    mod.TypeName = "铝材";
                        //    pathList.Add(mod);

                        //}
                        //else
                        //{
                        for (int count = 0; count < 5; count++)
                        {
                            Model.B_IE_PathTypeInfo mod = new Model.B_IE_PathTypeInfo();
                            if (count == 0)
                                continue;
                            else
                                path = ReplyPath + dailymodel.UPMAT.Trim() + "-" + count + ".tif";
                            mod.PathName = path;
                            mod.TypeName = "AP";
                            pathList.Add(mod);
                        }

                        //}

                    }

                    //}
                    plFillLeft.Controls.Clear();
                    ucShowPicList.LoadImageList(pathList);
                    ucShowPicList.Dock = DockStyle.Fill;
                    plFillLeft.Controls.Add(ucShowPicList);
                    txtAUFNR.Text = "";
                    txtAUFNR.Focus();
                    BaseFactory<B_PL_DailyWorkList>.Instance.ExecuteNonQuery(" update B_PL_DailyWorkList set RECORDFLAG=1,RECORDDATE=GETDATE(),RECORDUSER='" + Lamex.Common.Loginer.CurrentUser.Account + "' where AUFNR='" + OrderNum + "'");
                    //txtAUFNR.Text = "";
                }
            }
            else
            {
                XtraMessageBox.Show("不存在该单订号,请核对！");
                return;
            }
        }
        private void panelControl3_Resize(object sender,EventArgs e)
        {
            //sublb1Rigth.Left = (this.panelControl3.Width - sublb1Rigth.Width) / 2;
        }
        private void panelControl4_Resize(object sender, EventArgs e)
        {
            //sublb2.Left = (this.panelControl4.Width - sublb2.Width) / 2;
        }
        /// <summary>
        /// 正常显示
        /// </summary>
        /// <param name="PicSubA"></param>
        /// <param name="PicSubB"></param>
        /// <param name="PicA"></param>
        /// <param name="PicB"></param>
        private void NormalFibri(PictureEdit picEidtsubA, PictureEdit picEidtsubB, PictureEdit picEidtColorA, PictureEdit picEidtColorB, LabelControl sublb1Rigth, LabelControl sublb1, LabelControl sublb2, DataTable dt,int midLength,int h,int x,int y,int i)
        {
            if (!string.IsNullOrEmpty(dt.Rows[i]["COLORA"].ToString()))
            {
                Stream streamA = new MemoryStream((Byte[])dt.Rows[i]["COLORA"]);
                Bitmap bmtempA = new Bitmap(streamA);
                picEidtColorA.EditValue = new Bitmap(bmtempA, midLength, h);
            }
            else
            {
                picEidtColorA.EditValue = dt.Rows[i]["COLORA"];
            }
            picEidtColorA.Height = h;
            picEidtColorA.Margin = new Padding(0, 0, 0, 0);
            picEidtColorA.Location = new Point(x, y);
            picEidtColorA.Width = midLength;
            sublb1Rigth.Location = new Point(midLength*2 / 5, 0);

            //sublb1Rigth.Location = new Point(midLength, y);

            picEidtColorA.Controls.Add(sublb1Rigth);
            picEidtColorA.Controls.Add(sublb1);

            if(!string.IsNullOrEmpty(dt.Rows[i]["COLORB"].ToString()))
            {
                Stream streamB = new MemoryStream((Byte[])dt.Rows[i]["COLORB"]);
                Bitmap bmtempB = new Bitmap(streamB);
                picEidtColorB.EditValue = new Bitmap(bmtempB, midLength, h);
            }
            else
            {
                picEidtColorB.EditValue = dt.Rows[i]["COLORB"];
            }
            picEidtColorB.Height = h;
            picEidtColorB.Location = new Point(x, y);
            picEidtColorB.Width = midLength;
            picEidtColorB.Margin = new Padding(0, 0, 0, 0);
            sublb2.Location = new Point(midLength * 2 / 5, 0);
            //sublb2.Location = new Point(midLength, y);
            picEidtColorB.Controls.Add(sublb2);
        }
        /// <summary>
        /// 左边切割
        /// </summary>
        /// <param name="PicSubA"></param>
        /// <param name="PicSubB"></param>
        /// <param name="PicA"></param>
        /// <param name="PicB"></param>
        private void LeftFibri(PictureEdit picEidtsubA, PictureEdit picEidtsubB, PictureEdit picEidtColorA, PictureEdit picEidtColorB, LabelControl sublb1Rigth, LabelControl sublb1, LabelControl sublb2, DataTable dt, int midLength, int h, int x, int y, int i, string splitPath)
        {
            picEidtsubA.EditValue = ImageToBytes(splitPath);
            picEidtsubA.Width = midLength / 5;
            picEidtsubA.Dock = DockStyle.Left;
            picEidtsubA.Height = h - sublb1Rigth.Height;
            sublb1Rigth.Location = new Point(midLength * 2 / 5, 0);


            picEidtsubB.EditValue = ImageToBytes(splitPath);;
            picEidtsubB.Width = midLength / 5;
            picEidtsubB.Dock = DockStyle.Right;
            picEidtsubB.Height = h - sublb1Rigth.Height;

            if (!string.IsNullOrEmpty(dt.Rows[i]["COLORA"].ToString()))
            {
                Stream streamA = new MemoryStream((Byte[])dt.Rows[i]["COLORA"]);
                Bitmap bmtempA = new Bitmap(streamA);

                picEidtColorA.EditValue = new Bitmap(bmtempA, midLength, h); ;
            }
            else
            {
                picEidtColorA.EditValue = dt.Rows[i]["COLORA"];
            }
            
            picEidtColorA.Height = h;
            picEidtColorA.Margin = new Padding(0, 0, 0, 0);
            picEidtColorA.Location = new Point(x, y);
            picEidtColorA.Width = midLength;

            picEidtColorA.Controls.Add(sublb1Rigth);
            picEidtColorA.Controls.Add(sublb1);
            picEidtColorA.Controls.Add(picEidtsubA);
            if (!string.IsNullOrEmpty(dt.Rows[i]["COLORB"].ToString()))
            {
                Stream streamB = new MemoryStream((Byte[])dt.Rows[i]["COLORB"]);
                Bitmap bmtempB = new Bitmap(streamB);

                picEidtColorB.EditValue = new Bitmap(bmtempB, midLength, h);
            }
            else
            {
                picEidtColorB.EditValue = dt.Rows[i]["COLORB"];
            }
               
            picEidtColorB.Height = h;
            picEidtColorB.Location = new Point(x, y);
            picEidtColorB.Width = midLength;
            picEidtColorB.Margin = new Padding(0, 0, 0, 0);
            sublb2.Location = new Point(midLength * 2 / 5, 0);

            picEidtColorB.Controls.Add(sublb2);
            picEidtColorB.Controls.Add(picEidtsubB);

        }
        /// <summary>
        /// 左边切割
        /// </summary>
        /// <param name="PicSubA"></param>
        /// <param name="PicSubB"></param>
        /// <param name="PicA"></param>
        /// <param name="PicB"></param>
        private void RightFibri(PictureEdit picEidtsubA, PictureEdit picEidtsubB, PictureEdit picEidtColorA, PictureEdit picEidtColorB, LabelControl sublb1Rigth, LabelControl sublb1, LabelControl sublb2, DataTable dt, int midLength, int h, int x, int y, int i, string splitPath)
        {
            picEidtsubA.EditValue = ImageToBytes(splitPath); ;
            picEidtsubA.Width = midLength / 5;
            picEidtsubA.Dock = DockStyle.Right;
            picEidtsubA.Height = h - sublb1Rigth.Height;
            sublb1Rigth.Location = new Point(midLength * 2 / 5, 0);

            picEidtsubB.EditValue = ImageToBytes(splitPath);
            picEidtsubB.Width = midLength / 5;
            picEidtsubB.Dock = DockStyle.Left;
            picEidtsubB.Height = h - sublb1Rigth.Height;

            if (!string.IsNullOrEmpty(dt.Rows[i]["COLORA"].ToString()))
            {
                Stream streamA = new MemoryStream((Byte[])dt.Rows[i]["COLORA"]);
                Bitmap bmtempA = new Bitmap(streamA);
                picEidtColorA.EditValue = new Bitmap(bmtempA, midLength, h);
            }
            else
            {
                picEidtColorA.EditValue = dt.Rows[i]["COLORA"];
            }
            picEidtColorA.Height = h;
            picEidtColorA.Margin = new Padding(0, 0, 0, 0);
            picEidtColorA.Location = new Point(x, y);
            picEidtColorA.Width = midLength;

            picEidtColorA.Controls.Add(sublb1Rigth);
            picEidtColorA.Controls.Add(sublb1);
            picEidtColorA.Controls.Add(picEidtsubA);

            if (!string.IsNullOrEmpty(dt.Rows[i]["COLORB"].ToString()))
            {
                Stream streamB = new MemoryStream((Byte[])dt.Rows[i]["COLORB"]);
                Bitmap bmtempB = new Bitmap(streamB);

                picEidtColorB.EditValue = new Bitmap(bmtempB, midLength, h);
            }
            else
            {
                picEidtColorB.EditValue = dt.Rows[i]["COLORB"];
            }
            
            picEidtColorB.Height = h;
            picEidtColorB.Location = new Point(x, y);
            picEidtColorB.Width = midLength;
            picEidtColorB.Margin = new Padding(0, 0, 0, 0);
            sublb2.Location = new Point(midLength * 2 / 5, 0);
            picEidtColorB.Controls.Add(sublb2);
            picEidtColorB.Controls.Add(picEidtsubB);
        }
        private void DynamicLayout(TableLayoutPanel layoutPanel, int row, int col,DataTable dt)
        {

            //layoutPanel.RowCount = row;
            int height = layoutPanel.Height;
            int width = layoutPanel.Width;
            for (int i = 0; i < row; i++)
            {
                decimal h = decimal.Parse(height.ToString()) * decimal.Parse(dt.Rows[i]["Proportion"].ToString());
                layoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, Convert.ToInt32(h)));
            }
            layoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 20));//
            layoutPanel.ColumnCount = col;    //设置分成几列
            int w = width / 6;
            for (int i = 0; i < col-1; i++)
            {
                layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, w));
            }
        }
        private void txtAUFNR_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (string.IsNullOrEmpty(txtAUFNR.Text)) return;
            Model.B_PL_DailyWorkListInfo dailymodel = BaseFactory<B_PL_DailyWorkList>.Instance.GetEntriyList(" 1=1 and AUFNR='" + txtAUFNR.Text + "'").FirstOrDefault();
            List<Model.B_PL_AluminumFollowUpListInfo> alumList = BaseFactory<B_PL_AluminumFollowUpList>.Instance.GetEntriyList(" 1=1 and AUFN='" + txtAUFNR.Text + "'");
            List<Model.B_PL_FabricFollowUpListInfo> fabriList = BaseFactory<B_PL_FabricFollowUpList>.Instance.GetEntriyList(" 1=1 and AUFNR='" + txtAUFNR.Text + "'");
            
        }
        //每行数据行
        private DataRow GetRow(DataTable dt,string SortIndex, string PSKO_HEIGHT, string COLORA, string COLORB,string fibirlPath)
        {

            DataRow dr = dt.NewRow();
            dr["SortIndex"] = SortIndex;
            dr["PSKO_HEIGHT"] = PSKO_HEIGHT;
            string imagePath = fibirlPath + COLORA+".jpg";
            string imagePath2 = fibirlPath + COLORB + ".jpg";
            dr["COLORA"] = ImageToBytes(imagePath);
            dr["COLORAName"] = COLORA;
            dr["COLORB"] = ImageToBytes(imagePath2);
            dr["COLORBName"] = COLORB;
            
            return dr;
        }
        public static byte[] ImageToBytes(string imagePath)
        {
            if (!File.Exists(imagePath)) return null;
            FileStream files = new FileStream(imagePath, FileMode.Open);
            byte[] imgByte = new byte[files.Length];
            files.Read(imgByte, 0, imgByte.Length);
            files.Close();
            return imgByte;
            
        }

        private void tableLayOut_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
        {
            //Pen pp = new Pen(BorderColor);
            //e.Graphics.DrawRectangle(pp, e.CellBounds.X, e.CellBounds.Y, e.CellBounds.X + this.Width - 1, e.CellBounds.Y + this.Height - 1);
        }
        private Color borderColor = Color.Black;
        public Color BorderColor { get { return borderColor; } set { borderColor = value; } }

        private void gcView_MouseDown(object sender, MouseEventArgs e)
        {

        }

        private void gcView_Click(object sender, EventArgs e)
        {
            if (gridView2.RowCount <= 0) return;
            int iRow = gridView2.FocusedRowHandle;
            string pageName = gridView2.GetRowCellDisplayText(iRow, "DrawNum").ToString();
            ucShowPicList.SelectPageFocus(pageName);
        }
    }
}